package com.wnxy.service.impl;

import com.wnxy.dto.StatusCode;
import com.wnxy.dto.TicketsDto;
import com.wnxy.exception.OrderException;
import com.wnxy.model.Ticket;
import com.wnxy.mapper.TicketMapper;
import com.wnxy.service.TicketService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wnxy.util.BeanCopyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author alice
 * @since 2021-10-25
 */
@Service
public class TicketServiceImpl extends ServiceImpl<TicketMapper, Ticket> implements TicketService {
    @Autowired
    private StringRedisTemplate srt;
    @Autowired
    private RedisTemplate<String, Object> rt;
    @Override
    public TicketsDto getAll(Integer performId) {
        List<Object> ticketsObj = rt.opsForHash().values("wnxy:theater:ticket:" + performId);
        if(ticketsObj==null) throw new OrderException(StatusCode.ORDERERROR.getCode(), "演出信息不存在");
        List<Ticket> tickets = BeanCopyUtil.copyList(ticketsObj, Ticket.class);
        TicketsDto ticketsDto = new TicketsDto();
        ticketsDto.setTickets(tickets);
        return ticketsDto;
    }
}
